<?php
class Admin_Model_User extends Zend_Db_Table_Abstract{
	protected $_name = "users";
	protected $_primary = "uid";
	
	public function show_user(){
		$query = $this -> select();
		$query->from('users',array('user_id','email','password','first_name','last_name','get_newsletter','image','group_id'));
		$data = $this-> fetchAll($query);
		
		return $data -> toArray();
	}	
	
	public function show_user_member(){
		$query = $this -> select();
		$query->from('users',array('user_id','email','password','first_name','last_name','get_newsletter','image','group_id'));
		$query->where('group_id = 2');
		$data = $this-> fetchAll($query);
		return $data -> toArray();
	}
	
	public function show_user_where($id)
	{
		$query = $this -> select();
		$query->from('users',array('user_id','email','password','first_name','last_name','get_newsletter','image','group_id'));
		$query->where('user_id= ?', $id);
		$data = $this-> fetchAll($query);
		return $data -> toArray();
	}
	
	public function check_user($email)
	{
		$query = $this -> select();
		$query->from('users',array('user_id','email','password','first_name','last_name','get_newsletter','image'));
		$query->where('email= ?', $email);
		$data = $this-> fetchAll($query);
		$row = $data ->toArray(); 
		//print_r($row);die;
		if($row == NULL){
			return true;
		}else{
			return false;
		}
	}
	
	public function insert_user($data){
		try {
			$this->insert($data);
		} 
		catch (Exception $e) {
    		
		}
		
	}
	public function delete_user($id){
		try{
			$where="user_id=".$id;
    		$this->delete($where);
		}
		catch(Exception $e){
			
		}
	}

	public function update_user($id,$data){	
		try{	
			$where = "user_id=".$id;
			$this->update($data,$where);
		}
		catch(Exception $e){	
		}
	}
}